from multiprocessing import Process,Manager,Pool

import time

ls = ['a','b','c','d','e','f','g']
def write(q):
    # 将列表中元素写入队列中
    for i in ls:
        print('第{}几次写入'.format(i))
        q.put(i)
        time.sleep(2)

def read(q):
    print('开始读取')
    while True:
        if not q.empty():
            res = q.get()
            print(res)
            time.sleep(1)
        else:
            break

if __name__ == "__main__":
    q = Manager().Queue()
    pool = Pool(5)
    pool.apply(write,args=(q,))
    pool.apply(read,args=(q,))
    pool.close()
    pool.join()